Skip to content

Fix Enum.slice/2 for range with step > 1 sliced by step > 1#15144

Merged
josevalim merged 1 commit intoelixir-lang:mainfrom
pnezis:fix-enum-slice-range-step
Mar 7, 2026
Merged

Fix Enum.slice/2 for range with step > 1 sliced by step > 1#15144
josevalim merged 1 commit intoelixir-lang:mainfrom
pnezis:fix-enum-slice-range-step

Conversation

@pnezis
Copy link
Copy Markdown
Contributor

@pnezis pnezis commented Mar 6, 2026

When slicing a Range with step > 1 using a slice range that also has step > 1, the formula for calculating the step in the slicer function was incorrect.

Before

iex> Enum.slice(1..10//2, 0..4//2)
[1, 4, 7] # 4 is not even in the range

After

iex> Enum.slice(1..10//2, 0..4//2)
[1, 5, 9]

When slicing a Range with step > 1 using a slice range that also has
step > 1, the formula for calculating the step in the slicer function
was incorrect.
@pnezis pnezis force-pushed the fix-enum-slice-range-step branch from 40441d0 to 126d4ba Compare March 6, 2026 22:53
@josevalim josevalim merged commit 47d72d9 into elixir-lang:main Mar 7, 2026
15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@pnezis pnezis deleted the fix-enum-slice-range-step branch March 11, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants